<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php


class CConnectorUser implements IUserSourceInterface
{
    private $_initialized = false;
    
    public function  __construct()
    {
    }


    public function getUser($userInfo){
        $userName = $userInfo['userName'];
        $password = $userInfo['password'];

        $option = new OptionViewForm();
        $connector_url = $option->getOptionValue("connector_url");
        if (empty($connector_url)){
            return false;
        }

                                                
        if (strpos($connector_url, "?")){
            $connector_url = $connector_url."&name=".$userName."&password=".$password;
        } else {
            $connector_url = $connector_url."?name=".$userName."&password=".$password;
        }
    
        try {
            $data = @HttpClient::quickGet($connector_url);
        } catch (Exception $e) {
            return false;
        }
        
        if (!$data){
            return false;
        }

        try {
            $jsonData = @json_decode($data);
        } catch (Exception $e) {
            return false;
        }

        if (!isset($jsonData->success) || !$jsonData->success){
            return false;
        }

        $retData = array();
        $retData['user_name'] = $userName;
        if (isset($jsonData->nick)){
            $retData['nick']      = $jsonData->nick;
        }
        if (isset($jsonData->email)){
            $retData['email']     = $jsonData->email;
        }
        return $retData;
    }

    
    public function judgeSelf(){
        return false;
    }
}
?>